package com.demoo.zjsu.util.HttpClientUtil;

import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 采用设计模式后的微信获取openid方法
 * 大大增加了扩展性
 * 但是不是静态方法是这个的缺点
 */
@Service
public class WechatSender implements ClientSender{

//    @Resource(name = "requestConfig")
//    RequestConfig config;

    public HttpRequestBase getRequest(String url) {
        HttpGet get = new HttpGet(url);
//        get.setConfig(config);
        return get;
    }

    public String getEntity(CloseableHttpResponse response) {
        HttpEntity entity = response.getEntity();
        try {
            String result = EntityUtils.toString(entity, "UTF-8");
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
